package arm.util;

import java.util.Properties;

public class PropertiesUtil {
	
	private Properties prop;
	
	public PropertiesUtil(Properties prop)
	{
		this.prop=prop;
	}

	public String getStringProperty(String key)
	{
		return this.getStringProperty(key,null);
	}
	
	public String getStringProperty(String key,String def)
	{
		String value = prop.getProperty(key);
		if(value==null)
		{
			return value;
		}
		return value.length()==0?def:value.trim();
	}
	
	public boolean getBooleanProperty(String key,boolean def)
	{
		String value=prop.getProperty(key);
		return value==null?def:Boolean.valueOf(value).booleanValue();
	}
	
	public boolean getBooleanProperty(String key)
	{
		return this.getBooleanProperty(key, false);
	}
	
	public int getIntegerProperty(String key,int def) throws Exception
	{
		String value = prop.getProperty(key);
		if(value==null||value.equals(""))
		{
			return def;
		}
		try{
		return Integer.valueOf(value);
		}catch(Exception e)
		{
		   throw new Exception("value numberformatException"+e.getMessage());	
		}
	}
	
	public int getIntegerProperty(String key) throws Exception
	{
		return this.getIntegerProperty(key, 0);
	}
}
